import { _decorator, Component, director, Node } from "cc";
import { BombUILayer } from "./BombUILayer";
import { UIPlayer } from "./UI/UIPlayer";
const { ccclass, property } = _decorator;

@ccclass("GameManager")
export class GameManager extends Component {
  @property(Node)
  BombUILayer: Node = null;

  private static instance: GameManager;
  public static getInstance(): GameManager {
    return GameManager.instance;
  }

  //   private _bomb: number = 0;
  // 炸弹数量
  private bombNumber: number = 0;
  // 分数
  private score: number = 0;
  @property(UIPlayer)
  uiPlayer: UIPlayer = null;
  @property(Node)
  pauseButtonNode: Node = null;
  @property(Node)
  resumeButtonNode: Node = null;

  protected onLoad(): void {
    GameManager.instance = this;
  }
  start() {}
  addBomb() {
    this.bombNumber++;
    // this.BombUILayer.getComponent(BombUILayer).onUpdateBombNumber(
    //   this.bombNumber
    // );
    this.node.emit("updateBombNumber");
  }
  addScore(num: number) {
    this.score += num;
    this.node.emit("updateScore");
  }
  public static get bombNumber(): number {
    return GameManager.instance.bombNumber;
  }
  public static get score(): number {
    return GameManager.instance.score;
  }

  onClickPause() {
    director.pause();
    this.uiPlayer.setCanControl(false);
    this.pauseButtonNode.active = false;
    this.resumeButtonNode.active = true;
  }
  onCLickResume() {
    director.resume();
    this.uiPlayer.setCanControl(true);
    this.pauseButtonNode.active = true;
    this.resumeButtonNode.active = false;
  }

  update(deltaTime: number) {}
}
